package javax.realtime;

public abstract class Timer extends AsyncEvent {
	
	protected HighResolutionTime time;
	protected Clock clock;
	protected boolean absolute;
	protected boolean enabled;
	protected boolean active;
	
	protected Timer(HighResolutionTime time, Clock clock, AsyncEventHandler handler)
	{
		this.time = time;
		this.clock = clock;
		addHandler(handler);
		absolute = false;
		if(time instanceof AbsoluteTime) absolute = true;
		enabled = false;
		active = false;
	}
	
	public void addHandler(AsyncEventHandler handler)
	{
		;
	}

	public void disable()
	{
		enabled = false;
	}
	public void destroy()
	{
		stop();
	}
	public void enable()
	{
		if(active)
			enabled = true;
	}
	public Clock getClock()
	{
		return clock;
	}
	public boolean isRunning()
	{
		return active && enabled;
	}
	public void start()
	{
		if(active) throw new IllegalStateException();
		active = true;
		enabled = true;
	}
	public void start(boolean disabled)
	{
		enabled = !disabled;
	}
	public boolean stop()
	{
		if(active)
		{
			active = false;
			enabled = false;
			return true;
		}
		return false;
	}
}
